﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.Statistical;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem
{
  public partial class CommData : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      Response.Clear();
      int page = Request.Params["page"].ToInt32();
      int pagesize = Request.Params["rows"].ToInt32();
      string sort = Request.Params["sort"].ToRequestString();

      string orderby = HttpContext.Current.Request.QueryString["orderby"].ToRequestString();
      string tn = HttpContext.Current.Request.QueryString["tn"].ToRequestString();
      string year = HttpContext.Current.Request.QueryString["year"].ToRequestString();
      string month = HttpContext.Current.Request.QueryString["month"].ToRequestString();
      string dwbm = HttpContext.Current.Request.QueryString["dwbm"].ToRequestString();
      GridConfig gc = new GridConfig(tn, year, dwbm);
      string field = gc.SelectField;
      GridData data = new GridData(field, tn, dwbm, year, month, orderby);
      if (page == 0 && pagesize == 0)
      {
        string json = data.GetDataSet().Tables[0].ToJsonForGrid();

        Response.Write(json);
        Response.End();
      }
      else
      {
        //当数据为空时显示一条数据
        DataTable dt = data.GetDataSet().Tables[0];
        string json = "";

        if (dt.Rows.Count == 0)
        {
          DataRow dr = dt.NewRow();
          dr["NF"] = year;
          dr["YF"] = month;
          dr["DWBM"] = dwbm;
          dt.Rows.Add(dr);
        }

        json = dt.ToJsonForGrid(page, pagesize);
        Response.Write(json);
        Response.End();
      }
    }
  }
}